package cn.luckdou.WeChat.Dispatcher;

import cn.luckdou.WeChat.model.*;
import cn.luckdou.WeChat.utils.MessageUtil;
import cn.luckdou.WeChat.model.*;

import java.util.Map;

/**
 * @author Dadou 2017-12-5
 * 普通消息分发处理
 */

public class MsgDispatcher {


    public static String processMessage(Map<String, String> map) {
        String msgType = map.get("MsgType");

        //此处做一个统一回复
        if (msgType!=null){
            TextMessage textMessage=new TextMessage(map,"您发送的讯息已收到!");
            return MessageUtil.textMessageToXml(textMessage);
        }

        // 文本消息
        if (msgType.equals(MessageUtil.REQ_MESSAGE_TYPE_TEXT)) {
            return text(map);
        }

        // 图片消息
        if (msgType.equals(MessageUtil.REQ_MESSAGE_TYPE_IMAGE)) {
            return image(map);
        }

        // 链接消息
        if (msgType.equals(MessageUtil.REQ_MESSAGE_TYPE_LINK)) {
            return link(map);
        }

        // 位置消息
        if (msgType.equals(MessageUtil.REQ_MESSAGE_TYPE_LOCATION)) {
            return location(map);
        }

        // 视频消息
        if (msgType.equals(MessageUtil.REQ_MESSAGE_TYPE_VIDEO)) {
            return video(map);
        }

        // 语音消息
        if (msgType.equals(MessageUtil.REQ_MESSAGE_TYPE_VOICE)) {
            return voice(map);
        }

        return null;
    }

    /**
     * 图片消息
     * @param map
     * @return
     */
    private static String image(Map<String, String> map) {
        System.out.println("==============这是图片消息！");
        ImageMessage imageMessage= new ImageMessage(new Image(map.get("MediaId")),map);
        return MessageUtil.imageMessageToXml(imageMessage);
    }

    /**
     * 链接消息
     * @param map
     * @return
     */
    private static String link(Map<String, String> map) {
        System.out.println("==============这是链接消息！");
        return null;
    }

    /**
     * 位置消息
     * @param map
     * @return
     */
    private static String location(Map<String, String> map) {
        System.out.println("==============这是位置消息！");
        return null;
    }

    /**
     * 视频消息
     * @param map
     * @return
     */
    private static String video(Map<String, String> map) {
        System.out.println("==============这是视频消息！");

        return "视频消息";
    }

    /**
     * 语音消息
     * @return
     */
    private static String voice(Map<String, String> map) {
        System.out.println("==============这是语音消息！");
        VoiceMessage voiceMessage=new VoiceMessage(new Voice(map.get("MediaId")),map);
        String s = MessageUtil.voiceMessageToXml(voiceMessage);
        return s;
    }

    /**
     * 文本消息
     * @param map
     * @return
     */
    private static String text(Map<String, String> map) {
        System.out.println("==============这是文本消息！");
        TextMessage textMessage=new TextMessage(map,map.get("Content"));
        return MessageUtil.textMessageToXml(textMessage);
    }

}
